package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ResourceController
 * @Author loe
 * @Date 2024-07-14
 */

@RestController
@Api(tags = "资源管理")
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 资源列表查询
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("资源列表查询")
    @ApiOperationSupport(includeParameters = {"resourceDto.parentResourceNo", "resourceDto.resourceType"})
    public ResponseResult<List<ResourceVo>> getResourceList(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceVoList = resourceService.getResourceList(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    /**
     * 资源添加
     * @param resourceDto
     * @return
     */
    @PutMapping
    @ApiOperation("资源添加")
    @ApiOperationSupport(includeParameters = {
            "resourceDto.dataState",
            "resourceDto.icon",
            "resourceDto.parentResourceNo",
            "resourceDto.requestPath",
            "resourceDto.resourceName",
            "resourceDto.resourceType",
            "resourceDto.sortNo"
    })
    public ResponseResult insertResource(@RequestBody ResourceDto resourceDto) {
        resourceService.insertResource(resourceDto);
        return ResponseResult.success();
    }

    /**
     * 资源修改
     * @param resourceDto
     * @return
     */
    @PatchMapping
    @ApiOperation("资源修改")
    @ApiOperationSupport(includeParameters = {
            "resourceDto.dataState",
            "resourceDto.icon",
            "resourceDto.parentResourceNo",
            "resourceDto.requestPath",
            "resourceDto.resourceName",
            "resourceDto.resourceType",
            "resourceDto.sortNo",
            "resourceDto.id"
    })
    public ResponseResult updateResource(@RequestBody ResourceDto resourceDto) {
        resourceService.updateResource(resourceDto);
        return ResponseResult.success();
    }


    /**
     * 启用禁用
     * @param resourceDto
     * @return
     */
    @PostMapping("/enable")
    @ApiOperation("启用禁用")
    @ApiOperationSupport(includeParameters = {
            "resourceDto.dataState",
            "resourceDto.parentResourceNo",
            "resourceDto.resourceNo"
    })
    public ResponseResult setDataStatus(@RequestBody ResourceDto resourceDto) {
        resourceService.setDataStatus(resourceDto);
        return ResponseResult.success();
    }

    /**
     * 资源树形
     * @param resourceDto
     * @return
     */
    @PostMapping("/tree")
    @ApiOperation("资源树形")
    @ApiOperationSupport(includeParameters = {"resourceDto.label"})
    public ResponseResult<TreeVo> resourceTree(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTree(resourceDto);
        return ResponseResult.success(treeVo);
    }

    @DeleteMapping("/{menuId}")
    @ApiOperation("删除菜单")
    public ResponseResult deleteById(@PathVariable(required = true) String menuId) {
        resourceService.deleteById(menuId);
        return ResponseResult.success();
    }

    @GetMapping("/menus")
    @ApiOperation("动态菜单")
    public ResponseResult<List<MenuVo>> MotionMenu() {
        List<MenuVo> menuVoList = resourceService.getMotionMenu();
        return ResponseResult.success(menuVoList);
    }

}
